// pages/market/index.js 
Page({ 
 
    /** 
     * 页面的初始数据 
     */ 
    data: { 
      changeScrollTop:'',
      swiperCurrent:0, 
      //综合按钮
      selectAll:true,
      //销量按钮
      selectCount:false,
      //价格按钮
      selectPrice:false,
      //筛选弹出层是否显示
      sxShow:false, 
      /**
     * 筛选按钮图标
     */
      sxChange:false, 
      // 价格图标
      changePrice:false, 

      //重置判断
      allChecked: true,
      /**
     * 筛选规格列表
     */
      goodsSpecification: [
        {
          id: 1,
          title: "品项",
          type:"select",
          list: [
            {
              id: 1,
              name: "全部",
              isChecked: true,
            },
            {
              id: 2,
              name: "花冠",
              isChecked: false,
            },
            {
              id: 3,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 4,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 5,
              name: "贝智康A段",
              isChecked: false,
            },
            {
              id: 6,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 7,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 8,
              name: "A段",
              isChecked: false,
            }
            
          ]
        }, 
        {
          id:2,
          title:"价格区间",
          type:"minmax"
        },
        {
          id: 3,
          title: "品项",
          type: "select",
          list: [
            {
              id: 1,
              name: "全部",
              isChecked: true,
            },
            {
              id: 2,
              name: "花冠",
              isChecked: false,
            },
            {
              id: 3,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 4,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 5,
              name: "贝智康A段",
              isChecked: false,
            },
            {
              id: 6,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 7,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 8,
              name: "A段",
              isChecked: false,
            }

          ]
        }, 
        {
          id: 4,
          title: "品项",
          type: "select",
          list: [
            {
              id: 1,
              name: "全部",
              isChecked: true,
            },
            {
              id: 2,
              name: "花冠",
              isChecked: false,
            },
            {
              id: 3,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 4,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 5,
              name: "贝智康A段",
              isChecked: false,
            },
            {
              id: 6,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 7,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 8,
              name: "A段",
              isChecked: false,
            }

          ]
        },  
        {
          id: 5,
          title: "品项",
          type: "select",
          list: [
            {
              id: 1,
              name: "全部",
              isChecked: true,
            },
            {
              id: 2,
              name: "花冠",
              isChecked: false,
            },
            {
              id: 3,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 4,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 5,
              name: "贝智康A段",
              isChecked: false,
            },
            {
              id: 6,
              name: "贝智康",
              isChecked: false,
            },
            {
              id: 7,
              name: "林奇牧场",
              isChecked: false,
            },
            {
              id: 8,
              name: "A段",
              isChecked: false,
            }

          ]
        },    
      ],
      windowHeight:'',
      isFixed:false,
      // 菜单分类
      navClassify: [
        {
          id:1,
          title:'综合',
          type: 1,
        },
        {
          id: 2,
          title: '销量',
          type: 1,
        },
        {
          id: 3,
          title: '价格',
          type: 1,
        }
      ]
    }, 
   
    /** 
     * 生命周期函数--监听页面加载 
     */ 
    onLoad: function (options) { 
      wx.hideTabBar();
      //获取本页高度
      wx.getSystemInfo({
        success: (res) => {
          
          this.setData({
            windowHeight: res.windowHeight
          })
        },
      })
    }, 
   
    /** 
     * 生命周期函数--监听页面初次渲染完成 
     */ 
    onReady: function () { 
   
    }, 
   
    /** 
     * 生命周期函数--监听页面显示 
     */ 
    onShow: function () { 
    }, 
   
    /** 
     * 生命周期函数--监听页面隐藏 
     */ 
    onHide: function () { 
   
    }, 
   
    /** 
     * 生命周期函数--监听页面卸载 
     */ 
    onUnload: function () { 
   
    }, 
   
    /** 
     * 页面相关事件处理函数--监听用户下拉动作 
     */ 
    onPullDownRefresh: function () { 
   
    }, 
   
    /** 
     * 页面上拉触底事件的处理函数 
     */ 
    onReachBottom: function () { 
   
    }, 
   
    /** 
     * 用户点击右上角分享 
     */ 
    onShareAppMessage: function () { 
   
    }, 

    onPageScroll: function (e) {
      console.log(e.scrollTop);
    },
    // 轮播改变索引
    swiperChange: function (e) {
      let that = this;
      that.setData({
        swiperCurrent: e.detail.current
      })
    },

    //商品列表样式切换
    changeClass:function(){ 
      this.setData({ 
        sxChange: !this.data.sxChange, 
      }) 
    }, 
    //筛选按钮事件
    showSx:function () { 
      this.setData({ 
        sxShow: !this.data.sxShow, 
        changePrice: false, 
      }) 
    }, 
    //购物车事件
    goGoodsCard:function() { 
   
    }, 
  //筛选-重置按钮事件
  doResetting: function () {
    this.setData({
      chooseBtn: !this.data.chooseBtn,
    });
    let arr = this.data.goodsSpecification;
    arr.forEach(item => {
      if (item.list) {
        item.list.forEach(list => {
          this.setData({
            allChecked: false
          })
        });
      }
    });
  },
  //筛选-确定按钮事件
  goConfirm: function () {
    this.setData({
      chooseBtn: !this.data.chooseBtn,
      sxShow: !this.data.sxShow,
      allChecked: true,
    })
  },
  //综合按钮事件
  queryAll: function (e) {
    this.setData({
      selectAll: true,
      selectCount: false,
      selectPrice: false,
      changeScrollTop: 'good-search-select-box',
      changePrice: false,
    });
  },
  //销量按钮事件
  queryCount: function () {
    this.setData({
      selectAll: false,
      selectCount: true,
      selectPrice: false,
      changeScrollTop: 'good-search-select-box',
      changePrice: false 
    })
  },
  //价格按钮事件
  queryPrice: function () { 
    this.setData({ 
      changePrice: !this.data.changePrice, 
      selectAll: false,
      selectCount: false,
      selectPrice: true,
      changeScrollTop: 'good-search-select-box'
    }) 
  }, 
  // 筛选品类按钮事件
  sxChooseBtn: function (e) {
    let that = this;
    let father = e.currentTarget.dataset.father;
    let id = e.currentTarget.dataset.id;
    let goodsSpecification = that.data.goodsSpecification;
    goodsSpecification.forEach(item => {
      if( item.id == father){
        item.list.forEach(list => {
          if(list.id == id){
            list.isChecked = !list.isChecked;
          }else{
            list.isChecked = false;
          }
        });
      }
    });
    that.setData({
      allChecked: true,
      goodsSpecification: goodsSpecification,
    });
  },
  //固定搜索分类盒子
  layoutScroll: function (e) {
    // console.log(e.detail.scrollTop);
    let navTop = 150;
    if(e.detail.scrollTop >= navTop){
      this.setData({
        isFixed: true,
      })
    }else{
      this.setData({
        isFixed: false
      })
    }
  },
  /**
   * 点击商品
   */
  toDetail:function(){
    wx.navigateTo({
      url: '',
    })
  }
  
})